package com.zzy.eventbus.eventExtends;

import org.junit.Test;

import com.google.common.eventbus.EventBus;
/**
 * 如果Listener A 监听Event A,  而Event A 有一个子类Event B, 此时Listener A将同时接收Event A和B消息，实例如下：
 * @author Administrator
 *
 */
public class TestEventsFromSubclass {
	@Test
	public void testEventsFromSubclass() throws Exception {

		EventBus eventBus = new EventBus("test");
		
		IntegerListener integerListener = new IntegerListener();
		NumberListener numberListener = new NumberListener();
		
		eventBus.register(integerListener);
		eventBus.register(numberListener);

		
		//只有Integer是number的子类  
		eventBus.post(new Integer(100));

		System.out.println("integerListener message:" + integerListener.getLastMessage());
		System.out.println("numberListener message:" + numberListener.getLastMessage());

		
		//只有long是number的子类   -----integerListener不工作
		
		eventBus.post(new Long(200L));

		System.out.println("integerListener message:" + integerListener.getLastMessage());
		System.out.println("numberListener message:" + numberListener.getLastMessage());
	}
}

